#!/bin/bash
#一键安装K8S服务
source THEISPI.conf
set_host(){
	while [ -z "$hname" ];do
		echo '请输入此节点主机名(不得使用特殊符号,如 _ / \等等)'
		read hname
	done
	echo -e "The is Master Host?[y/n]\nDefault[N]"
	read htype
	bash k8s_install/config/hosts.sh
}
#set_host
export a=$1
k8s_config(){
	echo '待更新'
}
info(){
	cmmand="bash k8s_install/config/images_pull.sh"
	echo  -e "k8s installed\nIt is recommended to execute this command to pull the image\n${cmmand}"
}
k8s_install(){
        if [[ "$a" -eq "1" ]];then
                yum install -y kubelet kubectl kubeadm
        elif [[ "$a" -eq "2" ]];then
                apt-get install -y kubelet kubectl kubeadm
        fi
        if [[ "$?" -eq "0" ]];then
                echo 'docker-ce installed'
        else
                echo 'docker-ce  installation failed'
                exit 2
        fi
	systemctl enable kubelet
	systemctl start kubelet
	if [[ "$?" -eq "0" ]];then
		echo -e "K8S services runing"
		if [[ "$htype" == "y" || "$htype" == "Y" ]];then
			bash k8s_install/config/k8s.sh
		else
			echo 'services installed'
		fi
		echo "Config K8S[y/n][defalut N]"
		read ck8s
		if [[ "$ck8s" == "Y" || "$ck8s" == "y" ]];then
			bash  k8s_install/config/k8s.sh
		else
			echo 'Skip the K8S configuration'
		fi
		info
	else
		echo 'K8S services notruning'
	fi
}
if [[ "$network_status" -eq "yes" ]];then
        k8s_install
else
        exit 404
        echo 'network errors'
fi
